<?php
require("urlList.php");
require(dirname(__FILE__)."/includes/init.php");
if(isset($_SESSION['user_name'])){
$urls = '';
$url = '';
if (isset($_REQUEST['Submit'])) {
    $url = $_REQUEST['url'];
	$templateId = $_REQUEST['templateId'];
    $urlA = explode(".", $url);
	$r = rand(0,35);
	print_r($urlA);exit;
	if(preg_match("/www/",$urlA[0])){
		$urlA[0] = '';
		$urlA[1] = $urlArr[$r];
	}else{
		$urlA[0] = $urlArr[$r];
	}
	
    foreach ($urlA as $key => $value) {
        $urls = $urls.$value.".";
    }
    $urls = trim($urls, ".");
//	echo $urls;exit;
    $str = base64_encode($urls);
    $strs = "http://".$_SERVER['SERVER_NAME']."/click.php?u=".$str."&address=|*specifyEmail*|&templateId=".$templateId."";
}

if(isset($_REQUEST['Submit2'])){
	$emailAddress = $_REQUEST['emailAddress'];
	$type = $_REQUEST['type'];
	$emailId = $_REQUEST['emailId'];
	$trackUrl = "<img width=\"1\" height=\"1\" src=http://".$unsubUrlArr[0]."/open.php?m=".base64_encode($emailAddress."|".$emailId."|".$type."|").".jpg>";
}
?><title>格式化URL</title>

<form action="" method="post">
<table width="600" border="0" cellspacing="1" bgcolor="#CC0000">
  <tr bgcolor="#FFFFFF">
    <td>The URL: </td>
    <td><input name="url" type="text" style="width:450px; height:25px;" maxlength="300" /></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>Template Id: </td>
    <td colspan="2"><input name="templateId" type="text" id="templateId" style="width:450px; height:25px;" maxlength="300" /></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>原网址 :</td>
    <td><?php echo $url;?></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>替代后网址 : </td>
    <td><?php echo $urls;?></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>格式化后网址 : </td>
    <td><?php if(!empty($strs)){echo $strs;}else{echo "need url";}?></td>
  </tr>  
  <tr bgcolor="#FFFFFF">
    <td><p>|*UNSUB*|<br/>|*TRACK*|
	<br/>|*UPDATE*|<br/>|*specifyEmail*|</p></td>
    <td><input type="submit" name="Submit" value="Start" /></td>
  </tr>
</table>
</form>


<form action="" method="post">
<table width="600" border="0" cellspacing="1" bgcolor="#CC0000">
  <tr bgcolor="#FFFFFF">
    <td width="105">Email Address: </td>
    <td colspan="2"><input name="emailAddress" type="text" id="emailAddress" style="width:450px; height:25px;" maxlength="300" /></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>Email Type: </td>
    <td colspan="2"><input name="type" type="text" id="type" style="width:450px; height:25px;" maxlength="300" /></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>Email Id: </td>
    <td colspan="2"><input name="emailId" type="text" id="emailId" style="width:450px; height:25px;" maxlength="300" /></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>TrackLink : </td>
    <td colspan="2"><?php if(!empty($trackUrl)){echo htmlspecialchars($trackUrl);}else{echo "need url";}?></td>
  </tr>  
  <tr bgcolor="#FFFFFF">
    <td rowspan="4"><p>|*UNSUB*|<br/>|*TRACK*|
	<br/>|*UPDATE*|<br/>|*specifyEmail*|</p></td>
    <td width="85" rowspan="4"><input type="submit" name="Submit2" value="Start" /></td>
    <td width="400">999,表示跟踪发货; 888表示跟踪尚未付款的; </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>777,表示跟踪测试的邮件</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
  </tr>
</table>
</form>
<?php
}else{
 echo "hello";
}
?>